//
//  DingtouDetailViewController.m
//  HaoDeCaiFu
//
//  Created by 物联信息中心 on 2017/12/29.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "DingtouDetailViewController.h"
#import "LeftAndRightTableViewCell.h"
#import "InputPassWordView.h"//输入密码页面
#import "HDCFEditFixThrowViewController.h"//定投页面
#import "DingtouDetailTableViewCell.h"//执行情况的cell

static NSString * identifierOne = @"DingtouDetailTableViewCell";
@interface DingtouDetailViewController ()<InputPassWordViewDelegate>
{
    NSNumber * allTransactionAmount;//所有交易金额(累计定投金额)
    NSString * orderDate;//下单日期（上期扣款日）
    NSMutableArray * productsArray;//执行情况数组
}
@property(nonatomic,strong)UIView*tableHeaderView;
@property(nonatomic,strong)UIView*tableFooterView;
@property(nonatomic,strong)UILabel*yesterdayEarn;
@property(nonatomic,strong)UILabel*allEarnLabel;
@property(nonatomic,strong)NSArray*planDetailTitleArray;
@property(nonatomic,strong)NSArray*planDetailDataArray;
@property(nonatomic,strong)NSArray*titleArray;

@property (nonatomic, weak) UIView *hitView;
@property (nonatomic, copy) NSString *tradePassword;

@property (nonatomic,assign)NSInteger index;//判断点击的是那个按钮

@end

@implementation DingtouDetailViewController
-(void)setFixThrowPlanListModel:(FixThrowPlanListModel *)fixThrowPlanListModel
{
    _fixThrowPlanListModel = fixThrowPlanListModel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = _fixThrowPlanListModel.name;
    
    _index = 0;
    allTransactionAmount = 0;
    orderDate = @"-- --";
    productsArray = [[NSMutableArray alloc]init];
    self.planDetailTitleArray=@[@"定投时间",@"扣款失败是否顺延",@"上期扣款日",@"下期扣款日",@"绑定银行金卡"];
    
    NSString * cycleStr;//
    NSString * dayStr;
    if ([_fixThrowPlanListModel.cycle isEqualToString:@"weekly"]) {
        cycleStr = @"每星期";
        
        dayStr = [NSString stringWithFormat:@"星期%ld",(long)_fixThrowPlanListModel.cycleDay];
    }
    else if ([_fixThrowPlanListModel.cycle isEqualToString:@"biweekly"])
    {
        cycleStr = @"每两星期";
        dayStr = [NSString stringWithFormat:@"星期%ld",(long)_fixThrowPlanListModel.cycleDay];
    }
    else if ([_fixThrowPlanListModel.cycle isEqualToString:@"monthly"])
    {
        cycleStr = @"每月";
        dayStr = [NSString stringWithFormat:@"%ld日",_fixThrowPlanListModel.cycleDay];
    }
    else if ([_fixThrowPlanListModel.cycle isEqualToString:@"quarterly"])
    {
        cycleStr = @"每季";
        dayStr = [NSString stringWithFormat:@"%ld日",_fixThrowPlanListModel.cycleDay];
    }
    NSString * fixThrowTime = [NSString stringWithFormat:@"%@%@",cycleStr,dayStr];
    
    NSString * postponeDeductionStr;
    if ([_fixThrowPlanListModel.postponeDeduction isEqualToString:@"0"]) {
        postponeDeductionStr = @"否";
    }
    else if ([_fixThrowPlanListModel.postponeDeduction isEqualToString:@"1"])
    {
        postponeDeductionStr = @"是";
    }
    
    NSString * bankInfoStr = [NSString stringWithFormat:@"%@%@",_fixThrowPlanListModel.investorPayBankName,[self returnBankCardAmount:_fixThrowPlanListModel.investorPayBankAccountNumber]];
    self.planDetailDataArray=@[fixThrowTime,postponeDeductionStr,orderDate,[self timeFromStr:_fixThrowPlanListModel.nextRunDate],bankInfoStr];
    self.titleArray=@[@"计划详情",@"组合内基金",@"执行情况"];
    [self.tableView registerNib:[UINib nibWithNibName:@"LeftAndRightTableViewCell" bundle:nil] forCellReuseIdentifier:@"LeftAndRightTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DingtouDetailTableViewCell" bundle:nil] forCellReuseIdentifier:identifierOne];
    
    
    if ([_fixThrowPlanListModel.rspStatus isEqualToString:@"active"]) {
        //执行中
        NSArray*bottomArray=@[@"终止",@"修改",@"暂停"];
        for (NSInteger i=0; i<3; i++) {
            UIButton*bottomBtn=[UIButton buttonWithType: UIButtonTypeCustom];
            bottomBtn.frame=CGRectMake(screenWidth/3*i, screenHeight-50, screenWidth/3-1, 50);
            [bottomBtn setTitle:bottomArray[i] forState:UIControlStateNormal];
            bottomBtn.backgroundColor=COLOR_NAV;
            [bottomBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            bottomBtn.tag = 100 + i;
            [bottomBtn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            bottomBtn.titleLabel.font=[UIFont systemFontOfSize:15];
            [self.view addSubview:bottomBtn];
        }
    }
    else if ([_fixThrowPlanListModel.rspStatus isEqualToString:@"suspend"])
    {
        //已暂停
        NSArray*bottomArray=@[@"终止",@"修改",@"重启"];
        for (NSInteger i=0; i<bottomArray.count; i++) {
            UIButton*bottomBtn=[UIButton buttonWithType: UIButtonTypeCustom];
            bottomBtn.frame=CGRectMake(screenWidth/bottomArray.count*i, screenHeight-50, screenWidth/bottomArray.count-1, 50);
            [bottomBtn setTitle:bottomArray[i] forState:UIControlStateNormal];
            bottomBtn.backgroundColor=COLOR_NAV;
            [bottomBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            bottomBtn.tag = 100 + i;
            [bottomBtn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            bottomBtn.titleLabel.font=[UIFont systemFontOfSize:15];
            [self.view addSubview:bottomBtn];
        }
    }
    else if ([_fixThrowPlanListModel.rspStatus isEqualToString:@"terminated"])
    {
        //已终止
        self.tableView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
    }
    
    [self getDataOfFixThrowPlanList];
}
#pragma mark -
#pragma mark RequestData
-(void)getDataOfFixThrowPlanList
{
    [SVProgressHUD show];
    //获取用户定投计划执行情况历史纪录
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"accountNumber"] = kAcount;
    dict[@"rspId"] = [NSString stringWithFormat:@"%ld",_fixThrowPlanListModel.rspId];//定投计划代码,如提供，则返回过滤后的数据
    NSString *jsonString = [self dictionaryToJson:dict];
    NSDictionary *dictThree = @{
                                KparametOne:jsonString,
                                KparametTwo:@"/public/transaction/get-executive-condition-history-order-list"
                                };
    [HttpRequest sendGetRequestWithURL:nil WithParamets:dictThree success:^(id result)
    {
        [SVProgressHUD dismiss];
        //NSLog(@"%@",result);
        
        NSString * code = result[@"code"];
        if ([code isEqualToString:@"0000"]) {
            NSArray * dataArray = result[@"data"];
            if ([dataArray isKindOfClass:[NSNull class]] || dataArray.count <= 0)
            {
                [self.tableView setTableHeaderView:self.tableHeaderView];
                [self.tableView setTableFooterView:self.tableFooterView];
                return;
            }
            allTransactionAmount = dataArray[0][@"allTransactionAmount"];
            orderDate = dataArray[0][@"products"][0][@"orderDate"];
            //LLLog(@"%@",orderDate);
            for (int i = 0; i<dataArray.count; i++) {
                NSDictionary * dict = dataArray[i];
                NSArray * productsArr = [NSArray array];
                productsArr = dict[@"products"];
                
                [productsArray addObjectsFromArray:productsArr];
            }
            //一个section刷新
//            NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
//            [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
            [self.tableView reloadData];
            //创建headerView跟footerView
            [self.tableView setTableHeaderView:self.tableHeaderView];
            [self.tableView setTableFooterView:self.tableFooterView];
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
            //创建headerView跟footerView
            [self.tableView setTableHeaderView:self.tableHeaderView];
            [self.tableView setTableFooterView:self.tableFooterView];
        }
    } failure:^(NSError *errer) {
        //LLLog(@"%@",errer);
        [SVProgressHUD showErrorWithStatus:@"服务器错误，获取失败"];
        [SVProgressHUD dismissWithDelay:1.0];
        //创建headerView跟footerView
        [self.tableView setTableHeaderView:self.tableHeaderView];
        [self.tableView setTableFooterView:self.tableFooterView];
    }];
}
//暂停定投
-(void)stopFixThrowData
{
    //暂停定投
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"accountNumber"] = kAcount;
    dict[@"rspId"] = [NSString stringWithFormat:@"%ld",_fixThrowPlanListModel.rspId];//定投计划代码,如提供，则返回过滤后的数据
    dict[@"password"] = self.tradePassword;
    //LLLog(@"%@",dict);
    NSString *jsonString = [self dictionaryToJson:dict];
    NSDictionary *dictThree = @{
                                KparametTwo:@"/public/transaction/postpone-rsp-fund-plan"
                                };
    [SVProgressHUD show];
    [HttpRequest sendPostRequestWithURL:nil WithParamets:dictThree WithJsonString:jsonString success:^(id result) {
        [SVProgressHUD dismiss];
        NSLog(@"%@",result);
        
        if ([result[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD showSuccessWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误，获取失败"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
//终止定投请求
-(void)terminationFixThrowData
{
    //终止定投
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"accountNumber"] = kAcount;
    dict[@"rspId"] = [NSString stringWithFormat:@"%ld",_fixThrowPlanListModel.rspId];//定投计划代码,如提供，则返回过滤后的数据
    dict[@"password"] = self.tradePassword;
    //LLLog(@"%@",dict);
    NSString *jsonString = [self dictionaryToJson:dict];
    NSDictionary *dictThree = @{
                                KparametTwo:@"/public/transaction/terminate-rsp-fund-plan"
                                };
    [SVProgressHUD show];
    [HttpRequest sendPostRequestWithURL:nil WithParamets:dictThree WithJsonString:jsonString success:^(id result) {
        [SVProgressHUD dismiss];
        NSLog(@"%@",result);
        
        if ([result[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD showSuccessWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误，获取失败"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
//重启定投
-(void)restartFixThrowData
{
    //重启定投
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"accountNumber"] = kAcount;
    dict[@"rspId"] = [NSString stringWithFormat:@"%ld",_fixThrowPlanListModel.rspId];//定投计划代码,如提供，则返回过滤后的数据
    dict[@"password"] = self.tradePassword;
    //LLLog(@"%@",dict);
    NSString *jsonString = [self dictionaryToJson:dict];
    NSDictionary *dictThree = @{
                                KparametTwo:@"/public/transaction/restart-rsp-fund-plan"
                                };
    [SVProgressHUD show];
    [HttpRequest sendPostRequestWithURL:nil WithParamets:dictThree WithJsonString:jsonString success:^(id result) {
        [SVProgressHUD dismiss];
        NSLog(@"%@",result);
        
        if ([result[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD showSuccessWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.5];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误，获取失败"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}
-(void)bottomBtnClick:(UIButton *)but
{
    if (but.tag == 100) {
        
        _index = 1;
        //点击终止
        //先输入密码
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIView *view = [[UIView alloc] init];
        self.hitView = view;
        UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewHit)];
        r5.numberOfTapsRequired = 1;
        [view addGestureRecognizer:r5];
        
        view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
        view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
        InputPassWordView *inputView = [InputPassWordView InputPassWordView];
        inputView.frame = CGRectMake(30, (screenHeight - 182) / 2, screenWidth - 60, 182);
        inputView.layer.cornerRadius = 5.0;
        inputView.layer.shadowColor = ZKcolor(100, 100, 100).CGColor;//shadowColor阴影颜色
        inputView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
        inputView.layer.shadowOpacity = 0.7;//阴影透明度，默认0
        inputView.layer.shadowRadius = 3;//阴影半径，默认3
        inputView.clipsToBounds = YES;
        inputView.delegate = self;
        
        [view addSubview:inputView];
        [window addSubview:view];
    }
    else if (but.tag == 101)
    {
        //点击修改
        _index = 2;
        
        HDCFEditFixThrowViewController * fixThrowVC = [HDCFEditFixThrowViewController new];
        fixThrowVC.fixThrowPlanListModel = self.fixThrowPlanListModel;
        fixThrowVC.fixThrowManagerVC = self.fixThrowManagerVC;
        [self.navigationController pushViewController:fixThrowVC animated:YES];
    }
    else if (but.tag == 102)
    {
        //点击暂停
        _index = 3;
        //先输入密码
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UIView *view = [[UIView alloc] init];
        self.hitView = view;
        UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewHit)];
        r5.numberOfTapsRequired = 1;
        [view addGestureRecognizer:r5];
        
        view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
        view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
        InputPassWordView *inputView = [InputPassWordView InputPassWordView];
        inputView.frame = CGRectMake(30, (screenHeight - 182) / 2, screenWidth - 60, 182);
        inputView.layer.cornerRadius = 5.0;
        inputView.layer.shadowColor = ZKcolor(100, 100, 100).CGColor;//shadowColor阴影颜色
        inputView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
        inputView.layer.shadowOpacity = 0.7;//阴影透明度，默认0
        inputView.layer.shadowRadius = 3;//阴影半径，默认3
        inputView.clipsToBounds = YES;
        inputView.delegate = self;
        
        [view addSubview:inputView];
        [window addSubview:view];
    }
}
- (void)viewHit{
    [self.hitView removeFromSuperview];
}
-(UITableView*)tableView
{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight-50)];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.rowHeight=50;
        _tableView.sectionHeaderHeight=50;
        _tableView.sectionFooterHeight=5;
        _tableView.backgroundColor=ZKcolor(240, 240, 240);
        [_tableView setTableFooterView:[[UIView alloc]initWithFrame:CGRectZero]];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
-(UIView *)tableFooterView
{
    if (!_tableFooterView) {
        _tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 40)];
        UILabel * footerLabel = [[UILabel alloc]init];
        footerLabel.frame = CGRectMake(0, 0, screenWidth, 40);
        if (productsArray.count <= 0) {
            footerLabel.text = @"暂无数据";
        }
        else
        {
            footerLabel.text = @"没有更多数据";
        }
        
        footerLabel.backgroundColor = [UIColor whiteColor];
        footerLabel.font = [UIFont systemFontOfSize:14.0];
        footerLabel.textAlignment = NSTextAlignmentCenter;

        [_tableFooterView addSubview:footerLabel];
    }
    return _tableFooterView;
}
-(UIView*)tableHeaderView
{
    if (!_tableHeaderView) {
        _tableHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 90)];
        _tableHeaderView.backgroundColor=ZKcolor(240, 240, 240);
        
        UILabel *yesterdayEarn = [[UILabel alloc] init];
        yesterdayEarn.backgroundColor=[UIColor whiteColor];
        self.yesterdayEarn = yesterdayEarn;
     
        yesterdayEarn.frame = CGRectMake(0, 0, screenWidth / 2 - 1 , 80);
        yesterdayEarn.numberOfLines = 0;
        
        float touzijine = [_fixThrowPlanListModel.rspAmount floatValue];
        NSString *strleft = [NSString stringWithFormat:@"%.2f\n投资金额(元/期)",touzijine];
        ;
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:strleft];
        [attrStr addAttribute:NSFontAttributeName
                        value:[UIFont boldSystemFontOfSize:17]
                        range:NSMakeRange(0, strleft.length - 9)];
        [attrStr addAttribute:NSFontAttributeName
                        value:[UIFont systemFontOfSize:16]
                        range:NSMakeRange(strleft.length - 9, 9)];
        
        [attrStr addAttribute:NSForegroundColorAttributeName
                         value:[UIColor lightGrayColor]
                         range:NSMakeRange(strleft.length - 9, 9)];
        [attrStr addAttribute:NSForegroundColorAttributeName
                        value:ZKcolor(30, 30, 30)
                        range:NSMakeRange(0,strleft.length - 9)];
        
//        [attrStr addAttribute:NSForegroundColorAttributeName
//                        value:ZKcolor(30, 30, 30)
//                        range:NSMakeRange(0, strleft.length)];
        yesterdayEarn.textColor = [UIColor whiteColor];
        yesterdayEarn.attributedText = attrStr;
        yesterdayEarn.textAlignment = NSTextAlignmentCenter;
        //    yesterdayEarn.font = [UIFont systemFontOfSize:17];
        [_tableHeaderView addSubview:yesterdayEarn];
        
        UIView *sliderView = [[UIView alloc] init];
        sliderView.frame = CGRectMake(screenWidth / 2 - 1, 15, 1, 50);
        sliderView.backgroundColor = ZKcolor(240, 240, 240);
        [_tableHeaderView addSubview:sliderView];
        
        
        UILabel *allEarn = [[UILabel alloc] init];
        self.allEarnLabel = allEarn;
         allEarn.backgroundColor=[UIColor whiteColor];
        allEarn.frame = CGRectMake(screenWidth / 2, 0, screenWidth / 2 - 1 , 80);
        allEarn.numberOfLines = 0;
        
        
        NSString *strRight = [NSString stringWithFormat:@"%.2f\n累计定投金额(元)",[allTransactionAmount floatValue]];
        NSMutableAttributedString *attrStrT = [[NSMutableAttributedString alloc] initWithString:strRight];
        [attrStrT addAttribute:NSFontAttributeName
                         value:[UIFont boldSystemFontOfSize:17]
                         range:NSMakeRange(0, strRight.length - 9)];
        [attrStrT addAttribute:NSFontAttributeName
                         value:[UIFont systemFontOfSize:16]
                         range:NSMakeRange(strRight.length - 9, 9)];
        [attrStrT addAttribute:NSForegroundColorAttributeName
                         value:[UIColor lightGrayColor]
                         range:NSMakeRange(strRight.length - 9, 9)];
        
        
//        [attrStrT addAttribute:NSForegroundColorAttributeName
//                         value:ZKcolor(30, 30, 30)
//                         range:NSMakeRange(0, strRight.length)];
        allEarn.attributedText = attrStrT;
        allEarn.textAlignment = NSTextAlignmentCenter;
        [_tableHeaderView addSubview:allEarn];
        
        
    }
    return _tableHeaderView;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 5;
    }
    else if (section==1)
    {
        return 1;
    }
    else if (section == 2)
    {
        return 1+productsArray.count;
    }
    else
    {
        return 0;
    }
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView*bgView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 50)];
    bgView.backgroundColor=[UIColor whiteColor];
    
    UILabel*titileLable=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, screenWidth/2, 50)];
    titileLable.text=self.titleArray[section];
//    if (section!=2) {
//        titileLable.textColor=[UIColor lightGrayColor];
//    }
//    else
//    {
//        titileLable.textColor=ZKcolor(30, 30, 30);
//    }
    titileLable.textColor=ZKcolor(30, 30, 30);
    
    [bgView addSubview:titileLable];
    
    UIView*lineView=[[UIView alloc]initWithFrame:CGRectMake(0, 49.2, screenWidth, 0.8)];
    lineView.backgroundColor=ZKcolor(240, 240, 240);
    [bgView addSubview:lineView];
    
    return bgView;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 5)];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LeftAndRightTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"LeftAndRightTableViewCell"];
    if (!cell) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"LeftAndRightTableViewCell" forIndexPath:indexPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    DingtouDetailTableViewCell *detailCell=[tableView dequeueReusableCellWithIdentifier:identifierOne];
    if (!detailCell) {
        detailCell=[tableView dequeueReusableCellWithIdentifier:identifierOne forIndexPath:indexPath];
    }
    detailCell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    if (indexPath.section==0) {
        cell.titleLable.text=self.planDetailTitleArray[indexPath.row];
        cell.dataLable.text=self.planDetailDataArray[indexPath.row];
        
        if (indexPath.row == 2) {
            //LLLog(@"%@",orderDate);
            if ([[NSString stringWithFormat:@"%@",orderDate] isEqualToString:@"-- --"]) {
                cell.dataLable.text= orderDate;
            }
            else
            {
                cell.dataLable.text=[self timeFromStr:[NSString stringWithFormat:@"%ld",[orderDate integerValue]]];
            }
        }
        
        return cell;
    }
    else  if (indexPath.section==1) {
        cell.titleLable.text=[NSString stringWithFormat:@"%@  %@",_fixThrowPlanListModel.fundCode,_fixThrowPlanListModel.fundName];
        cell.titleLable.adjustsFontSizeToFitWidth = YES;
        cell.titleLable.textColor=[UIColor lightGrayColor];
        cell.dataLable.text=@"100%";
        cell.dataLable.textColor=COLOR_NAV;
        
        return cell;
    }
    else if (indexPath.section==2)
    {
        if (indexPath.row == 0) {
            //默认cell
        }
        else {
            if (productsArray.count > 0) {
                NSDictionary * productsDic = productsArray[indexPath.row-1];
                //LLLog(@"%@",productsDic);
                detailCell.firstLabel.text = [NSString stringWithFormat:@"%@",[self timeFromStr:productsDic[@"transactionDate"]]?[self timeFromStr:productsDic[@"transactionDate"]]:@""];
                detailCell.secondLabel.text = [NSString stringWithFormat:@"%@",productsDic[@"transactionAmount"]?productsDic[@"transactionAmount"]:@""];
                
                if ([productsDic[@"transactionStatus"] isEqualToString:@"failure"]) {
                    detailCell.thirdLabel.text=@"支付失败";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"received"])
                {
                    detailCell.thirdLabel.text=@"下单成功";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"priced"])
                {
                    detailCell.thirdLabel.text=@"确认成功";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"completed"])
                {
                    detailCell.thirdLabel.text=@"交易成功";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"ipo.processing"])
                {
                    detailCell.thirdLabel.text=@"认购确认成功";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"pending.payment"])
                {
                    detailCell.thirdLabel.text=@"等待付款";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"canceling"])
                {
                    detailCell.thirdLabel.text=@"撤单中";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"canceled"])
                {
                    detailCell.thirdLabel.text=@"已撤单";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"pending.void"])
                {
                    detailCell.thirdLabel.text=@"等待退款";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"void"])
                {
                    detailCell.thirdLabel.text=@"交易失败";
                }
                else if ([productsDic[@"transactionStatus"] isEqualToString:@"payment"])
                {
                    detailCell.thirdLabel.text=@"过渡中";
                }
                else
                {
                    detailCell.thirdLabel.text=@"";
                }
            }
        }
        return detailCell;
    }
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
#pragma mark -
#pragma mark InputPassWordViewDelegate
- (void)cancelClick{
    [self.hitView removeFromSuperview];
}
- (void)confirmClickWithPassWord:(NSString *)password{
    self.tradePassword = password;
    [self.hitView removeFromSuperview];
    if (password.length < 1) {
        [SVProgressHUD showInfoWithStatus:@"请输入交易密码"];
        [SVProgressHUD dismissWithDelay:1.0];
        return;
    }
    
    if (_index == 1) {
        [self terminationFixThrowData];
        //终止定投
    }
    else if(_index == 2)
    {
        //修改定投
        
    }
    else if(_index == 3)
    {
        if ([_fixThrowPlanListModel.rspStatus isEqualToString:@"active"]) {
            //进行中 可以暂停定投
            [self stopFixThrowData];
        }
        else if ([_fixThrowPlanListModel.rspStatus isEqualToString:@"suspend"])
        {
            //暂停中 可以重启定投
            [self restartFixThrowData];
        }
    }
    
    
    
}
#pragma mark -
#pragma mark 字典转json字符串
- (NSString *)dictionaryToJson:(NSDictionary *)dic{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString *jsonTemp = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return jsonTemp;
}
#pragma mark -
#pragma mark 时间戳转化成标准时间
-(NSString *)timeFromStr:(NSString *)time
{
    //时间戳转化成时间
    NSDateFormatter *stampFormatter = [[NSDateFormatter alloc] init];
    [stampFormatter setDateFormat:@"YYYY/MM/dd"];
    //以 1970/01/01 GMT为基准，然后过了secs秒的时间
    NSDate *stampDate = [NSDate dateWithTimeIntervalSince1970:[time integerValue]/1000];
    return [stampFormatter stringFromDate:stampDate];
}
-(NSString *)returnBankCardAmount:(NSString * )bankCoadStr
{
    NSString *numberString = [bankCoadStr stringByReplacingCharactersInRange:NSMakeRange(4, 4) withString:@"*"];
    
    return numberString;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
